/**
 * 中介模式
 */

class MiddleMan{
    constructor(tenant,landlord) {
        this.tenant = tenant
        this.landlord = landlord
    }
    sendLandlord(money){
        this.tenant.money -=money
        this.landlord.money+=money
        
    }
    sendTenant(money){
        this.landlord.money -=money
        this.tenant.money+=money
    }
}

class Person{
    constructor(name,money){
        if(new.target==Person){
            throw new Error('cannot new Person')
        }
        this.name = name
        this.money = money
    }
}

class Tenant extends Person{
    constructor(name,money){
        super(name,money)
    }

    payDesposit(money,middle){
        middle.sendLandlord(money)
    }

    payRent(money,middle){
        middle.sendLandlord(money)
    }
}

class Landlord extends Person{
    constructor(name,money){
       super(name,money)
    }
    refundDesposit(money,middle){
        middle.sendTenant(money)
    }
}

const t = new Tenant('gao',100)
const l = new Landlord('five',1000000000000)
const middle = new MiddleMan(t,l)
t.payDesposit(10,middle)
t.payRent(50,middle)
l.refundDesposit(10,middle)
console.log('交易完毕')

